package com.nowcoder.code.lcof;

import com.algorithm.model.ListNode;

public class JZ18 {

    public static void main(String[] args) {
    }


    public ListNode deleteNode(ListNode head, int val) {

        if (head == null) {
            return head;
        }
        if (head.val == val) {
            return head.next;
        }

        ListNode res = head;
        ListNode last;
        while (res.next != null) {
            last = res;
            res = res.next;
            if (res.val == val) {
                last.next = res.next;
                break;
            }
        }
        return head;
    }

}
